/*
 * Copyright 2010 Piotr Buda
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package li.buda.cqflex.validate {
import mx.utils.StringUtil;

public class Validate {
    /**
     * Default message for Validate#notNull method when the <code>message</code> argument is ommited.
     * @default "The validated object [{0}] is null."
     */
    public static var DEFAULT_NULL_OBJECT_MESSAGE:String = "The validated object [{0}] is null.";

    /**
     * Validates whether an object is not <code>null</code>.
     * If it is <code>null</code> a <code>ValidateError</code> error is raised.
     * If <code>message</code> argument is null or ommited, a default message is applied.
     * @param obj object to validate
     * @param message meaningful message for the <code>ValidateError</code> error
     * @throws li.buda.cqflex.validate.ValidateError
     */
    public static function notNull(obj:*, message:String = null):void {
        if (obj == null) {
            if (message == null) {
                throw new ValidateError(StringUtil.substitute(DEFAULT_NULL_OBJECT_MESSAGE, obj));
            }
            throw new ValidateError(message);
        }
    }

    public function Validate() {
        throw new Error("This is a static class, please don't instantiate it.");
    }
}
}